package com.example.sleep;

import sun.awt.windows.ThemeReader;

/**
 * @author:CrazyShaQiuShi
 * @email:3105334046@qq.com
 * @descript: 关于线程沉睡
 * @version:1.0.0
 */
public class ThreadSleep {
    public static void main(String []args) throws InterruptedException {
        Thread thread=new Thread(){
            @Override
            public void run() {
                while (true){
                    if(Thread.currentThread().isInterrupted()){
                        System.out.println("删库跑路...");
                        break;
                    }
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                        System.out.println("Interrupted When sleep");
                        //设置中断状态
                        Thread.currentThread().interrupt();

                    }
                    Thread.yield();
                }
            }
        };
        thread.start();
        Thread.sleep(1000);
        thread.interrupt();
    }
}
